package cn.weekimwee.firstlineofcodeforkotlin.unit9.network

import cn.weekimwee.firstlineofcodeforkotlin.App
import org.jetbrains.anko.toast

/**
 * 返回结果的基类
 * Created by Wee Kim Wee on 2018/4/8.
 */
data class ReturnInfo<out T>(private val code: Int, private val msg: String, private val data: T?) {

    fun handleResult(onSuccessCallBack: (data: T?) -> Unit) {
        if (code == 200) {
            onSuccessCallBack.invoke(data)
        } else {
            App.INSTANCE.toast(msg)
        }
    }

    fun hanleResult(onSuccessCallBack: (data: T?) -> Unit, onErrorCallback: (msg: String) -> Unit) {
        if (code == 200) {
            onSuccessCallBack.invoke(data)
        } else {
            onErrorCallback.invoke(msg)
        }
    }
}